package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.work.WorkEntryBO;
import com.ymk.core.code.cmd.WorkEntryCmdCode;
import com.ymk.service.IWorkEntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class WorkEntryListCmd extends ACmd {

    @Override
    public CmdSign executeMop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkEntryBO reqData = super.getData(sign, WorkEntryBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("uId",reqData.getUId())
                .addParam("userName",reqData.getUserName())
                .addParam("mobile",reqData.getMobile())
                .addParam("idCardNo",reqData.getIdCardNo())
                .addParam("isEntry",reqData.getIsEntry())
            .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<WorkEntryBO> respDataList = this.WorkEntryService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }
    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        WorkEntryBO reqData = super.getData(sign, WorkEntryBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("userId",reqData.getUserId())
                .addParam("isEntry",reqData.getIsEntry())
                .setReturnStruct(sign.getReturnStruct());
        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());
        List<WorkEntryBO> respDataList = this.WorkEntryService.listForPage(pagination);
        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public boolean anon(CmdSign sign) {
        return true;
    }

    @Override
    public String getCmdCode() {
        return WorkEntryCmdCode.WORK_ENTRY_LIST;
    }

    @Autowired
    private IWorkEntryService WorkEntryService;
}